﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class StateManagement : System.Web.UI.Page
{
    private int i = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        //Response.Write("Counter1 = " + Session["Counter1"]);
        //Response.Write("<br/>");
        //Response.Write("Counter2 = " + Session["Counter2"]);

        if (Request.Cookies["Counter1"] != null)
            Response.Write("Counter1 = " + Request.Cookies["Counter1"].Value);
        Response.Write("<br/>");
        if (Request.Cookies["Counter2"] != null)
            Response.Write("Counter2 = " + Request.Cookies["Counter2"].Value);
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        //Session["Counter1"] = Session["Counter2"] = ++i;
        Response.Cookies["Counter1"].Value = (++i).ToString();
        Response.Cookies["Counter2"].Value = i.ToString();
        Response.Cookies["Counter2"].Path = "/Demo";
    }
}